package com.yanqu.road.server.cmd.kuang.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.kuang.Kuang;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = GameProtocol.S_KUANG_GET_RANK_REWARD_FROM_CROSS, desc = "领奖回包")
public class KuangGetRankRewardFromCrossCmd extends AbstractCommand {

    private Kuang.CrossKuangGetRankRewardRespMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = Kuang.CrossKuangGetRankRewardRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        Kuang.KuangBattleGetRankRewardRespMsg.Builder respMsg = Kuang.KuangBattleGetRankRewardRespMsg.newBuilder();
        if (reqMsg.getRet() == 0 && reqMsg.hasReward()) {
            // 获得奖励
            player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseStringToProperty(reqMsg.getReward()), eLogMoneyType.Kuang, eLogMoneyType.KuangGetRankReward);
            respMsg.setReward(reqMsg.getReward());
        }
        respMsg.setRet(reqMsg.getRet());
        player.sendPacket(ClientProtocol.U_KUANG_GET_RANK_REWARD, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
